﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Pong_Project.Game_objects
{
    /// <summary>
    /// A powerup that can be picked up by the bats
    /// </summary>
    class PowerupBat : Powerup
    {
        private Bat bat;
        private Ball ball;
        private float scaleFactor;
        private Vector2 directionModifyer;

        public PowerupBat(GameObjectIdentity identity, Bat bat, Bat batAffected, Ball ballAffected, int timeToLast, int timeToLive, int minTimeBeforeSpawning, int maxTimeBeforeSpawning, float scaleFactor, Vector2 directionModifyer)
            : base(identity, bat, new Vector2(0, 0), timeToLast, timeToLive, minTimeBeforeSpawning, maxTimeBeforeSpawning)
        {
            this.bat = batAffected;
            this.ball = ballAffected;
            this.scaleFactor = scaleFactor;
            this.directionModifyer = directionModifyer;
        }

        public override void Spawn()
        {
            base.Spawn();
            int nextBat = Game.Random.Next(4);

            if (nextBat <= 1)
                PositionX = 1;
            else
                PositionX = Game.WindowWidth - 8;

            if (nextBat == 0 || nextBat == 3)
                PositionY = Game.WindowHeight - Height - 10;
            else
                PositionY = 10;
        }


        public override void ApplyEffect(GameObject gameObject)
        {
            base.ApplyEffect(gameObject);

            if (directionModifyer != Vector2.Zero)
            {
                if (gameObject.Identity == GameObjectIdentity.BatRight)
                    ball.VelocityX = directionModifyer.X;
                else
                    ball.VelocityX = -directionModifyer.X;

                ball.VelocityY = Game.Random.Next(-2, 2);
            }

            if (scaleFactor != 0)
            {
                ball.ScaleX *= scaleFactor;
            }
        }

        public override void RemoveEffect()
        {
            base.RemoveEffect();

            if (scaleFactor != 0)
                ball.ScaleX /= scaleFactor;
        }

        public override void Reset()
        {
            base.Reset();

            if (scaleFactor != 0)
                ball.ScaleX = 1.0f;
        }
    }
}
